package concurrent.reentrantLock;

import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo {
    private static Integer i = 0;

    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock(true);
        new Thread(() -> {
            for (int j = 0; j < 10; j++) {
                lock.lock();
                System.out.println("线程1输出：" + ReentrantLockDemo.i++);
                lock.unlock();
            }
        }).start();

        new Thread(() -> {
            for (int j = 0; j < 10; j++) {
                lock.lock();
                System.out.println("线程2输出：" + ReentrantLockDemo.i++);
                lock.unlock();
            }
        }).start();
    }
}
